package com.uyaer.wheel.display.widget
{
	import com.uyaer.wheel.common.Common;
	import com.uyaer.wheel.plus.Audio;
	import com.uyaer.wheel.res.ResManager;
	import com.uyaer.wheel.utils.Utils;
	
	import starling.animation.Transitions;
	import starling.core.Starling;
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.text.TextField;
	
	public class Hit extends Sprite
	{
		private var tf:TextField;
		public function Hit()
		{
			this.layout();
		}
		
		private function layout():void{
			var bg:Image = new Image(ResManager.me.getTexture("menu_hit"));
			addChild(bg);
			
			tf = new TextField(bg.width,bg.height,"0 HIT",Common.HitFONT,20,0xff9900);
			addChild(tf);
		}
		
		public function updateHit(hitCount:int):void{
			tf.text = hitCount+"HIT";
		}
		
		public function show(x:Number,y:Number):void{
			this.alpha = 1;
			var that:Hit = this;
			//左右飞出
			if(Utils.probability(0.5)){
				this.x = Utils.probability(0.5)?0:Common.W;
				this.y = Utils.rangInt(0,Common.H);
			}else{ //上下飞出
				this.x = Utils.rangInt(0,Common.W);
				this.y = Utils.probability(0.5)?0:Common.H;
			} 
			Starling.juggler.tween(that,0.85,{"x":x,"y":y,rotation:-2*Math.PI,"transition":Transitions.EASE_OUT,
						"onComplete":function():void{
							Starling.juggler.tween(that,0.45,{"alpha":0,"delay":1.2,"onComplete":function():void{
								HitPool.recycleHit(that);
							}});
						}});
			Audio.me.playHit();
		}
	}
}